import matplotlib.pyplot as plt
import matplotlib

# 设置中文字体和解决负号显示问题
matplotlib.rcParams['font.sans-serif'] = ['SimHei']  # 使用黑体显示中文
matplotlib.rcParams['axes.unicode_minus'] = False    # 解决负号 '-' 显示为方块的问题

# # 激励频率 (kHz)
# frequencies = [0.1, 0.2, 3.5, 7.5, 10, 13.5, 15.5, 17, 19, 21, 23, 25, 27, 29, 32, 37, 40, 45, 50]

# # 对应的电压值 (V)
# voltages = [5.16, 5.16, 5.28, 5.48, 5.48, 5.00, 4.44, 4.04,
#             3.48, 2.90, 2.48, 2.14, 1.86, 1.62, 1.34, 0.98,
#             0.84, 0.68, 0.54]

# # 激励频率 (kHz)
# frequencies = [0.1, 0.2, 3.5, 7.5, 10, 13.5, 15.5, 17, 19, 21, 23, 25, 27, 29, 32, 37, 40, 45, 50]

# # 对应的电压值 (V)
# voltages = [5.16, 5.16, 4.52, 3.00, 2.26, 1.56, 1.23, 1.07,
#             0.90, 0.76, 0.52, 0.56, 0.49, 0.43, 0.36, 0.27,
#             0.23, 0.18, 0.15]

# # 激励频率 (kHz)
# frequencies = [0.1, 0.2, 3.5, 7.5, 10, 13.5, 15.5, 17, 19, 21, 23, 25, 27, 29, 32, 37, 40, 45, 50]

# # 对应的电压值 (V)
# voltages = [0.13, 0.23, 3.30, 4.72, 4.74, 4.36, 4.08, 3.90,
#             3.64, 3.36, 3.14, 2.96, 2.78, 2.64, 2.44, 2.16,
#             2.00, 1.80, 1.64]

# 激励频率 (kHz)
frequencies = [0.1, 0.2, 3.5, 7.5, 10, 13.5, 15.5, 17, 19, 21, 23, 25, 27, 29, 32, 37, 40, 45, 50]

# 对应的电压值 (V)
voltages = [0.70, 0.24, 1.26, 2.82, 3.80, 4.56, 4.68, 4.60,
            4.40, 4.10, 3.84, 3.56, 3.26, 3.04, 2.76, 2.36,
            2.20, 1.94, 1.74]


# 绘制折线图
plt.figure(figsize=(10, 6))
plt.plot(frequencies, voltages, marker='o', linestyle='-', color='b', label='电压变化')

# 添加标题和坐标轴标签（中文）
plt.title('电压随激励频率的变化')
plt.xlabel('频率 (kHz)')
plt.ylabel('电压 (Vopp)')

# 网格显示
plt.grid(True)

# 显示图例
plt.legend()

# 自动调整布局
plt.tight_layout()

# 显示图形
plt.show()